/**
 * Copyright &copy; 2012-2016 <a href="https://istep.lczyfz.com">Istep</a> All rights reserved.
 */
package com.lczyfz.istep.modules.scene.service;

import com.lczyfz.istep.common.persistence.Page;
import com.lczyfz.istep.common.service.CrudService;
import com.lczyfz.istep.modules.scene.dao.SceneSecurityGroupDao;
import com.lczyfz.istep.modules.scene.entity.SceneSecurityGroup;
import com.lczyfz.istep.modules.scene.entity.SceneVmTemplate;
import com.lczyfz.istep.modules.sys.entity.User;
import com.lczyfz.istep.modules.sys.utils.UserUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 安全组管理Service
 * @author dh
 * @version 2017-03-28
 */
@Service
@Transactional(readOnly = true)
public class SceneSecurityGroupService extends CrudService<SceneSecurityGroupDao, SceneSecurityGroup> {

	public SceneSecurityGroup get(String id) {
		return super.get(id);
	}
	
	public List<SceneSecurityGroup> findList(SceneSecurityGroup sceneSecurityGroup) {
		return super.findList(sceneSecurityGroup);
	}
	
	public Page<SceneSecurityGroup> findPage(Page<SceneSecurityGroup> page, SceneSecurityGroup sceneSecurityGroup) {
		return super.findPage(page, sceneSecurityGroup);
	}
	
	@Transactional(readOnly = false)
	public void save(SceneSecurityGroup sceneSecurityGroup) {
		super.save(sceneSecurityGroup);
	}
	
	@Transactional(readOnly = false)
	public void delete(SceneSecurityGroup sceneSecurityGroup) {
		super.delete(sceneSecurityGroup);
	}
	public SceneSecurityGroup findSecurityGroupByName(SceneSecurityGroup sceneSecurityGroup)
	{
		return dao.findSecurityGroupByName(sceneSecurityGroup);
	}
	public void preInsert(SceneSecurityGroup info) {

		User user = UserUtils.getUser();
		if (StringUtils.isNotBlank(user.getId())) {
			info.setUpdateBy(user);
			info.setCreateBy(user);
		}
		Date date=new Date();
		info.setUpdateDate(date);
		info.setCreateDate(date);

	}
	@Transactional(readOnly = false)
	public void insert(SceneSecurityGroup sceneSecurityGroup) {
		dao.insert(sceneSecurityGroup);
	}

	public SceneSecurityGroup findByEnvironmentId(String environmentId)
	{
		return  dao.findByEnvironmentId(environmentId);
	}

	public 	List<SceneSecurityGroup> findSGListByEnvironmentId(String DEL_FLAG_NORMAL,String id)
	{
		return dao.findSGListByEnvironmentId(DEL_FLAG_NORMAL,id);
	}
	public List<SceneSecurityGroup> findVmSgList(SceneVmTemplate sceneVmTemplate)
	{
		return dao.findVmSgList(sceneVmTemplate);
	}
}